<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");require_once("../config/pagecls.php");require_once("pwd1cls.php");

if($action=='del'){
	$db->delete("{$db_prefix}applyup","id='$id'");
	echo "<script>location.href='user_uplst.php?pageno={$pageno}';</script>";exit();
}

$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
$rshy=$db->get_one($sqlhy);
var_dump($rshy);
exit;
$pos=$rshy['pos'];$oldrank=$rshy['rank'];
$hytjuser=$rshy['tjuser'];

if($act=='hyup'){
	$msg='';
	if(trim($rank)=='') $msg.="请选择升级级别\\n";
	if(trim($rshy['rank'])==count($hyrankary)) $msg.="您已经是最高会员级别了\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//是否有同样的升级申请
	$sqlchk="select id from {$db_prefix}applyup where username='".$_SESSION["sys_username"]."' and state=0";
	$rschk=$db->get_one($sqlchk);
	if ($rschk['id']){
		$msg.="您已经提交了升级申请。不能重复提交\\n\\n请耐心等待管理员审核";
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	
	//本次升级需要多少报单款
	$glornamebd="glo_regprice_".$rshy['rank'];
	$glornamebd1="glo_regprice_".$rank;
	$sjneedprice=$$glornamebd1-$$glornamebd;
	//可以累积多少业绩
	$glornameyj="glo_regpv_".$rshy['rank'];
	$glornameyj1="glo_regpv_".$rank;
	$sjljyj=$$glornameyj1-$$glornameyj;
	$glornameyj="glo_regnum_".$rshy['rank'];
	$glornameyj1="glo_regnum_".$rank;
	$sjljnum=$$glornameyj1-$$glornameyj;
	
	//升级不需要审核
	$state=0;$edittime=0;
	if ($glo_hyupneedsh==0){
		$state=1;$edittime=$curtime;
		//升级是否扣报单款
		if ($glo_hyupkbdprice==1){
			if ($rshy['price']<$sjneedprice){
				$msg.="升级需要{$sjneedprice}美金\\n\\n您的报单币钱包不足\\n";
				echo "<script>alert('$msg');history.back();</script>";exit();
			}
			//扣除会员的报单币钱包
			$sqlkk="update {$db_prefix}users set rank='$rank',price=price-'$sjneedprice' where id='".$_SESSION['sys_userid']."'";
			$db->query($sqlkk);
			//财务记录
			$e_userid=$_SESSION['sys_userid'];$e_price=-$sjneedprice;$e_type=7;$e_ptype=1;$e_addtime=$curtime;$e_memo="会员升级";
			hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
		}
		
		//升级是否累积业绩
		if ($glo_hyupljpv==1){
			//获取会员的管理网it
			$sqlgx="select * from {$db_prefix}glgx where userid='".$_SESSION["sys_userid"]."'";
			$rsgx=$db->get_one($sqlgx);
			$glstr=$rsgx['glstr'];
			///////////////
			//管理网体业绩
			if ($glstr){
				$curday=date("Y-m-d",$curtime);
				$glnetary=explode(',',$glstr);
				$glnetnum=count($glnetary);
				foreach($glnetary as $k1=>$v1){
					if(($k1+1)==$glnetnum){
						$leftyj1=0;$leftyj2=0;$leftnum1=0;$leftnum2=0;$tjyj=0;$tjnum=0;
						$glornameyj="leftyj{$pos}";
						$$glornameyj=$sjljyj;
						$glornameyj1="leftnum{$pos}";
						$$glornameyj1=$sjljnum;
					}else{
						$leftyj1=0;$leftyj2=0;$leftnum1=0;$leftnum2=0;$tjyj=0;$tjnum=0;
						//会员处理什么区位
						$sqlqw="select pos from {$db_prefix}users where id='".$glnetary[$k1+1]."'";
						$rsqw=$db->get_one($sqlqw);
						$glornameyj="leftyj".$rsqw['pos'];
						$$glornameyj=$sjljyj;
						$glornameyj1="leftnum".$rsqw['pos'];
						$$glornameyj1=$sjljnum;
					}
					updatehytdyj($curday,$v1,$leftyj1,$leftyj2,$leftnum1,$leftnum2,$tjyj,$tjnum);
				}
			}
			//获取会员的推荐网it
			$sqlgx="select * from {$db_prefix}tjgx where userid='".$_SESSION["sys_userid"]."'";
			$rsgx=$db->get_one($sqlgx);
			$tjstr=$rsgx['tjstr'];
			//推荐网体业绩
			if ($tjstr){
				$curday=date("Y-m-d",$curtime);
				$tjnetary=explode(',',$tjstr);
				foreach($tjnetary as $k1=>$v1){
					$leftyj1=0;$leftyj2=0;$leftnum1=0;$leftnum2=0;$tjyj=$sjljyj;$tjnum=$sjljnum;
					updatehytdyj($curday,$v1,$leftyj1,$leftyj2,$leftnum1,$leftnum2,$tjyj,$tjnum);
				}
			}
			//注册成功
			///////////////
			//注册成功
			$iskong=0;
			$tjsnum=0;
			//会员是第几个推荐数
			$sqltjs="select count(id) as c from {$db_prefix}users where id<'".$_SESSION['sys_userid']."' and tjuser='$hytjuser'";
			$rstjs=$db->get_one($sqltjs);
			$tjsnum=intval($rstjs['c']);
			$tjuser=$hytjuser;
			$regmoney=$sjneedprice;$regnum=$sjljnum;
			$rank0=0;$username=$_SESSION["sys_username"];
			
			require("../entera.php");
		}
		//升级是否累积业绩
		
	}
	
	//是否已经超过了8个结算周内
	//插入到数据库中
	$dataArray['username']=$_SESSION['sys_username'];
	$dataArray['oldrank']=$oldrank;
	$dataArray['newrank']=$rank;
	$dataArray['addtime']=$curtime;
	$dataArray['state']=$state;
	$dataArray['edittime']=$edittime;
	$db->insert("{$db_prefix}applyup",$dataArray);
	
	//更新会员的级别
	if ($glo_hyupneedsh==0){
		echo "<script>alert('会员升级成功');location.href='user_uplst.php';</script>";exit();
	}else{
		echo "<script>alert('升级申请已经提交\\n\\n请等待管理员审核');location.href='user_uplst.php';</script>";exit();
	}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
font-size:12px;
}
.red{
	color:#FF0000
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">会员升级记录</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2">
		<?
		if ($rshy['rank']==count($hyrankary)){
		?>
		现在级别是[ <?=$hyrankary[$rshy['rank']]?> ]！<BR>
		您已经是最高级别了！
		<?
		}else{
		?>
				  <form id="form1" name="form1" method="post" action="?act=hyup">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td colspan="3"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                            <tr>
                              <td class="left_bt2"><label class="red">
                                <?
				  if ($glo_hyupneedsh==1) echo "会员升级需要管理员审核";else echo "会员升级不需要管理员审核。请自行升级";
				  ?>
                              </label></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3"><table width="100%" height="90" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td height="30" align="center" class="left_txt">会员</td>
                              <td height="30" class="left_txt"><?=$rshy['username']?></td>
                            </tr>
                            <tr>
                              <td height="30" align="center" class="left_txt">现在级别</td>
                              <td height="30" class="left_txt"><?=$hyrankary[$rshy['rank']]?></td>
                            </tr>
                            <tr>
                              <td height="30" align="center" class="left_txt">升级到级别</td>
                              <td height="30" class="left_txt"><label>
                                <select name="rank">
                                  <?
					foreach($hyrankary as $k1=>$v1){
						if($rshy['rank']<$k1){
							echo "<option value='{$k1}'>{$v1}</option>";
						}
					}
					?>
                                </select>
                                <span class="red">* </span></label></td>
                            </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3" align="center" class="red"><?
			  if ($glo_hyupkbdprice==1) echo "您的账户报单币钱包:".$rshy['price']."美金";
			  ?>
                        </td>
                      </tr>
                      <tr>
                        <td width="50%" height="30" align="right"><input type="submit" value="申请升级" name="B1" /></td>
                        <td width="6%" height="30" align="right">&nbsp;</td>
                        <td width="44%" height="30">&nbsp;</td>
                      </tr>
                      <tr>
                        <td height="30" colspan="3">&nbsp;</td>
                      </tr>
                    </table>
                  </form>
				  <?
				  }
				  ?>
				  </td>
                </tr>
              </table></td>
            </tr>
            <tr style="display:none">
              <td height="30"><table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                  <td align="center" bgcolor="#f2f2f2" >会员</td>
                  <td align="center" bgcolor="#f2f2f2" >老级别</td>
                  <td align="center" bgcolor="#f2f2f2" >新级别</td>
                  <td align="center" bgcolor="#f2f2f2" >状态</td>
                  <td align="center" bgcolor="#f2f2f2" >申请时间</td>
                  <td align="center" bgcolor="#f2f2f2" >审核时间</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
  <?
  $query='';
  if ($action=='query'){
  	
  }
  $sql="select count(id) as c  from {$db_prefix}applyup where username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}applyup where username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>
                  <td align="center"><?=$rs['username']?></td>
                  <td align="center"><?=$hyrankary[$rs['oldrank']]?></td>
                  <td align="center"><?=$hyrankary[$rs['newrank']]?>                      </td>
                  <td align="center" ><? if($rs['state']==0) echo "未处理";elseif($rs['state']==1) echo "已升级";else echo "已拒绝";?></td>
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                  <td align="center" ><? if ($rs['edittime']>0) echo date("Y-m-d H:i:s",$rs['edittime'])?></td>
                  <td height="30" align="center" ><a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">删除</a></td>
                  </tr>
	<?
  }
  $db->free_result($result);
  ?>
              </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right">每页<?=$page->pagesize?>条 第<?=$page->pageno?>/<?=$page->pagenum?>页 共<?=$page->recnum?>条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr style="display:none">
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
